function A = bwCenter(bwimg,ok)
% 获取目标质心
%   ok = 0,二值图像取反
A(2) = 0;
[x,y] = size(bwimg);
if ok == 0
    bwimg = 1 - bwimg;
end
STATS = regionprops(bwimg,'Area','Centroid');
%假定目标区域面积最大
len = length(STATS);
if len == 0
    A(1) = x/2;
    A(2) = y/2;
    return;
elseif length(STATS) ~= 1
    [~,index] = max(STATS.Area);
    A(1) = STATS(index).Centroid(1);
    A(2) = STATS(index).Centroid(2);
else
    A(1) = STATS.Centroid(1);
    A(2) = STATS.Centroid(2);
end
% imshow(bwimg)
% hold on
% plot(x,y,'r*');
end

